package cn.openbiotoken.impl;

import cn.openbiotoken.Pose;

import static java.lang.String.format;

/**
 * 姿态
 */
public class PoseImpl implements Pose {

    /**
     * @param yaw 偏航角
     * @param roll 横滚角
     * @param pitch 俯仰角
     */
    public PoseImpl(final float yaw, final float roll, final float pitch) {

        if (yaw < MIN_YAW) {
            throw new IllegalArgumentException(format("The yaw should be greater than or equal to %f. Actual yaw is %f.", MIN_YAW, yaw));
        }
        if (yaw > MAX_YAW) {
            throw new IllegalArgumentException(format("The yaw should be less than or equal to %f. Actual yaw is %f.", MAX_YAW, yaw));
        }

        if (roll < MIN_ROLL) {
            throw new IllegalArgumentException(format("The roll should be greater than or equal to %f. Actual roll is %f.", MIN_ROLL, roll));
        }
        if (roll > MAX_ROLL) {
            throw new IllegalArgumentException(format("The roll should be less than or equal to %f. Actual roll is %f.", MAX_ROLL, roll));
        }

        if (pitch < MIN_PITCH) {
            throw new IllegalArgumentException(format("The pitch should be greater than or equal to %f. Actual pitch is %f.", MIN_PITCH, pitch));
        }
        if (pitch > MAX_PITCH) {
            throw new IllegalArgumentException(format("The pitch should be less than or equal to %f. Actual pitch is %f.", MAX_PITCH, pitch));
        }

        this.yaw = yaw;
        this.roll = roll;
        this.pitch = pitch;
    }

    private final float yaw;

    private final float roll;

    private final float pitch;

    @Override
    public float getYaw() {
        return yaw;
    }

    @Override
    public float getRoll() {
        return roll;
    }

    @Override
    public float getPitch() {
        return pitch;
    }
}
